package com.ruoyi.merchant.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.merchant.domain.ImsFinance;
import com.ruoyi.merchant.service.IImsFinanceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 财务信息管理
 * 
 * @author ruoyi
 * @date 2024-09-07
 */
@RestController
@RequestMapping("/finance")
public class ImsFinanceController extends BaseController
{
    @Autowired
    private IImsFinanceService imsFinanceService;

    /**
     * 查询【财务信息】列表
     */
    @PreAuthorize("@ss.hasPermi('system:finance:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImsFinance imsFinance)
    {
        startPage();
        List<ImsFinance> list = imsFinanceService.selectImsFinanceList(imsFinance);
        return getDataTable(list);
    }

    /**
     * 导出【财务信息】列表
     */
    @PreAuthorize("@ss.hasPermi('system:finance:export')")
    @Log(title = "【财务信息】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImsFinance imsFinance)
    {
        List<ImsFinance> list = imsFinanceService.selectImsFinanceList(imsFinance);
        ExcelUtil<ImsFinance> util = new ExcelUtil<ImsFinance>(ImsFinance.class);
        util.exportExcel(response, list, "【财务信息】数据");
    }

    /**
     * 获取【财务信息】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:finance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(imsFinanceService.selectImsFinanceById(id));
    }

    /**
     * 新增【财务信息】
     */
    @PreAuthorize("@ss.hasPermi('system:finance:add')")
    @Log(title = "【财务信息】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImsFinance imsFinance)
    {
        return toAjax(imsFinanceService.insertImsFinance(imsFinance));
    }

    /**
     * 修改【财务信息】
     */
    @PreAuthorize("@ss.hasPermi('system:finance:edit')")
    @Log(title = "【财务信息】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImsFinance imsFinance)
    {
        return toAjax(imsFinanceService.updateImsFinance(imsFinance));
    }

    /**
     * 删除【财务信息】
     */
    @PreAuthorize("@ss.hasPermi('system:finance:remove')")
    @Log(title = "【财务信息】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imsFinanceService.deleteImsFinanceByIds(ids));
    }

    /**
     * 统计【财务信息】数量
     */
    @PreAuthorize("@ss.hasPermi('system:finance:list')")
    @GetMapping("/getEchartsCount")
    public AjaxResult getEchartsCount(ImsFinance imsFinance)
    {
        startPage();
        Map map = new HashMap();
        List<ImsFinance> list = imsFinanceService.getEchartsCount(imsFinance);
        List<String> descList = new ArrayList();
        List<Long> countList = new ArrayList();
        if (list != null && !list.isEmpty()) {
            for (ImsFinance finance : list) {
                descList.add(finance.getName());
                countList.add(finance.getValue());
            }
        }
        List<ImsFinance> echartsCountByDept = imsFinanceService.getEchartsCountByDept(imsFinance);
        List<String> descDeptList = new ArrayList();
        List<Long> countDeptList = new ArrayList();
        if (echartsCountByDept != null && !echartsCountByDept.isEmpty()) {
            for (ImsFinance finance : echartsCountByDept) {
                descDeptList.add(finance.getName());
                countDeptList.add(finance.getValue());
            }
        }
        map.put("list", list);
        map.put("countList", countList);
        map.put("descList", descList);
        map.put("echartsCountByDept", echartsCountByDept);
        map.put("countDeptList", countDeptList);
        map.put("descDeptList", descDeptList);
        return AjaxResult.success(map);
    }
}
